#include "tinyxml2.h"
#include <iostream>
#include <regex>
#include <string>

using namespace tinyxml2;
using std::cout;
using std::endl;
using std::regex;
using std::string;


void test()
{
    XMLDocument doc;
	doc.LoadFile( "coolshell.xml" );//加载文件
    if(doc.ErrorID())
    {
        std::cerr << "LoadFile error" << endl;
        return;
    }
#if 0
    XMLElement* titleElement = doc.FirstChildElement( "rss" )
        ->FirstChildElement("channel")
        ->FirstChildElement("item")
        ->FirstChildElement("title");
	const char* title = titleElement->GetText();
    cout << "title = " << title << endl;

    XMLElement* titleElement1 = doc.FirstChildElement( "rss" )
        ->FirstChildElement("channel")
        ->FirstChildElement("item")
        ->FirstChildElement("link");
	const char* link = titleElement1->GetText();
    cout << "link = " << link << endl;
#endif
    XMLElement* root = doc.FirstChildElement( "rss" )
        ->FirstChildElement("channel")
        ->FirstChildElement("item");

    /* const char *title = root->FirstChildElement("title")->GetText(); */
    /* const char *link = root->FirstChildElement("link")->GetText(); */
    /* const char *des = root->FirstChildElement("description")->GetText(); */
    /* const char *content = root->FirstChildElement("content:encoded")->GetText(); */
    string title = root->FirstChildElement("title")->GetText();
    string link = root->FirstChildElement("link")->GetText();
    string des = root->FirstChildElement("description")->GetText();
    string content = root->FirstChildElement("content:encoded")->GetText();


    regex rgx("<[^>]+>");
    des = std::regex_replace(des, rgx, "");
    content = std::regex_replace(content, rgx, "");

    cout << "title = " << title << endl;
    cout << "link = " << link << endl;
    cout << "des  = " << des << endl;
    cout << "content = " << content << endl;

}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

